﻿using System.Windows.Forms;
using KillBill.Business.Entities;
using KillBill.Presentation.Common.WindowsForms.View;
using KillBill.Presentation.Modules.Administration.IView;
using KillBill.Presentation.Modules.Administration.Presenter;


namespace KillBill.Presentation.Modules.Administration.View
{
    public partial class CustomerEditView : KillBillWinFormView, ICustomerEdit
    {
        private bool _editMode;

        public CustomerEditView()
        {
            InitializeComponent();
            Presenter = new CustomerEditPresenter(this);
            _editMode = false;
        }
        public CustomerEditView(Customer customer)
        {
            InitializeComponent();
            Presenter = new CustomerEditPresenter(customer,this);
            _editMode = true;
        }

       

        private CustomerEditPresenter _presenter;
        #region ICustomerEdit Members

        public CustomerEditPresenter Presenter { get; set; }

        public string Address
        {
            get
            {
                return txbxAddress.Text;
            }
            set
            {
                txbxAddress.Text = value;
            }
        }

        public string Email
        {
            get
            {
                return txbxEmail.Text;
            }
            set
            {
                txbxEmail.Text = value;
            }
        }

        public string FirstName
        {
            get
            {
                return txbxFistName.Text;
            }
            set
            {
                txbxFistName.Text = value;
            }
        }

        public string LastName
        {
            get
            {
                return txbxLastName.Text;
            }
            set
            {
                txbxLastName.Text = value;
            }
        }

        public string Phone
        {
            get
            {
                return txbxPhone.Text;
            }
            set
            {
                txbxPhone.Text = value;
            }
        }

        public string CustomerRUC
        {
            get
            {
                return txbxCustomerRuc.Text;
            }
            set
            {
                txbxCustomerRuc.Text = value;
            }
        }

        public bool IsActive
        {
            get
            {
                return cbxActive.Checked;
            }
            set
            {
                cbxActive.Checked = value;
            }
        }

        public string CustomerID
        {
            get
            {
                return txbxPersonId.Text;
            }
            set
            {
                txbxPersonId.Text = value;
            }
        }

        public string Reference
        {
            get
            {
                return txbxReference.Text;
            }
            set
            {
                txbxReference.Text = value;
            }
        }

        #endregion

        private void btnAcept_Click(object sender, System.EventArgs e)
        {
            if (PanelCustomer.IsValid)
            {
                if (_editMode)
                    Presenter.EditCustomer();
                else
                    Presenter.SaveCustomer();
            }
            else
                ShowMessage("Los Datos ingresados son incorrectos...");
        }

        private void btnCancel_Click(object sender, System.EventArgs e)
        {
            this.Close();
        }

        private void CustomerEditView_Load(object sender, System.EventArgs e)
        {

        }


        public new void ShowMessage(string message)
        {
            MessageBox.Show(message);
        }
    }
}
